#pragma once
#include "yzrutil.h"
#include "DSP.h"

namespace yzrilyzr_dsp{
	ECLASS(DSPGroup, public DSP){
	public:
	std::vector<std::shared_ptr<DSP>> dsps;
	DSPGroup(){}
	DSPGroup(std::vector<std::shared_ptr<DSP>> &dsps1){
		for(auto & d : dsps1){
			if(d == nullptr) continue;
			this->dsps.push_back(d);
		}
	}
	void init(u_sample_rate sampleRate)override{
		for(auto & d : dsps){
			if(d == nullptr) continue;
			d->init(sampleRate);
		}
	}
	void resetMemory()override{
		for(auto & d : dsps){
			if(d == nullptr) continue;
			d->resetMemory();
		}
	}
	void add(std::shared_ptr<DSP> dsp){
		dsps.push_back(dsp);
	}
	DSP & get(u_index i){
		return *dsps[i];
	}
	void remove(u_index i){
		dsps.erase(dsps.begin() + i);
	}
	void clear(){
		dsps.clear();
	}
	u_index size()const{
		return dsps.size();
	}
	std::vector<std::shared_ptr<DSP>> & getDsps(){
		return dsps;
	}
	void cloneParam(DSP * obj1)override{
		if(auto other=dynamic_cast<DSPGroup *>(obj1)){
			for(uint32_t i=0;i < dsps.size();i++){
				dsps[i]->cloneParam(other->dsps[i].get());
			}
		}
	}
	virtual yzrilyzr_lang::String toString()const override;
	};
}